import React, { Component, createRef } from "react";
import PropTypes from "prop-types";
export default class TodoInput extends Component {
  constructor() {
    super();
    this.inputRef = createRef();
  }
  static defaultProps = {
    placeholder: "请输入代办事项",
    btnText: "添加",
  };
  static propTypes = {
    placeholder: PropTypes.string.isRequired,
    btnText: PropTypes.string.isRequired,
  };
  render() {
    return (
      <div>
        <input
          type="text"
          placeholder={this.props.placeholder}
          ref={this.inputRef}
        />
        <input
          type="button"
          value={this.props.btnText}
          onClick={() => this.handleAddTodos()}
        />
      </div>
    );
  }
  handleAddTodos() {
    this.props.click(this.inputRef.current.value);
    this.inputRef.current.value = "";
    this.inputRef.current.focus();
  }
}

// TodoHeader.defaultProps = {
//   placeholder: "请输入代办事项",
//   btnText: "添加",
// };

// TodoHeader.propTypes = {
//   placeholder: PropTypes.string.isRequired,
//   btnText: PropTypes.string.isRequired,
// };
